import moment from 'moment'
import _ from 'lodash'
/**
 * @param {*} time
 * @return {string}
 */
export function toTime (time) {
  return _.isNil(time) || time === '--' ? '--' : moment(time).format('YYYY-MM-DD HH:mm:ss')
}

/**
 * @param {*} date
 * @return {string}
 */
export function toDate (date) {
  return _.isNil(date) ? '--' : moment(date).format('YYYY-MM-DD')
}

/**
 * null undefined to '--'
 * @param {*} str
 * @return {string}
 */
export function toHorizontalLine (str) {
  return (_.isNil(str) || str === '') ? '--' : str
}

/**
 * @param {*} num 数字
 * @return {string}
 */
export function toLtMore (num) {
  if (_.isNil(num)) return ''
  return num > 99 ? '99+' : num
}

/**
 * @param {*} date
 * @return {string}
 * 相差一天, 两天, 显示今天明天
 */
export function toNewDate (date) {
  let member
  const newDate = ['今天', '昨天']
  let day = moment(moment().format('YYYY-MM-DD')).diff(moment(moment(date).format('YYYY-MM-DD')), 'day')
  member = day < 2 ? `${newDate[day]} ${moment(date).format('HH:mm:ss')}` : moment(date).format('YYYY-MM-DD HH:mm:ss')
  return member
}

export default {
  toTime,
  toDate,
  toHorizontalLine,
  toLtMore,
  toNewDate
}
